<!DOCTYPE html>
<html  class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">
    <head>
        <meta charset="UTF-8">
        <title>PingPangTask-0.1</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <base th:href="@{/}">
        <link rel="stylesheet" href="static/css/font.css">
        <link rel="stylesheet" href="static/css/xadmin.css">
        <script src="static/lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="static/js/xadmin.js"></script>
        <!--[if lt IE 9]>
          <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
          <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>
    
    <body>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">

                <div class="layui-col-md12">

                    <div class="layui-card">
					
                            <form class="layui-form layui-col-space5" id="sreach">
								<div class="layui-input-inline layui-show-xs-block">
                                    <select name="logStatus">
                                        <option value="">所有</option>
                                        <option value="0">成功</option>
                                        <option value="-1">失败</option>
                                    </select>
                                </div>
                                
                                <div class="layui-input-inline layui-show-xs-block">
                                <select name="taskRunID">
                                 <option value="">所有</option>
	                             <option 
		                           th:each="taskRun : ${taskRunList}"
		                           th:value="${taskRun.id}"
		                           th:text="${taskRun.name}"
		                          >
                                </select> 
                                </div>
                                
                                <div class="layui-input-inline layui-show-xs-block">
                                    <input type="text" name="logClass" placeholder="类名" autocomplete="off" class="layui-input"></div>
                                
                                <div class="layui-input-inline layui-show-xs-block">
                                    <input type="text" name="logMethod" placeholder="方法名" autocomplete="off" class="layui-input"></div>
                                        
								<div class="layui-input-inline layui-show-xs-block">
                                    <input type="text" name="logIPPort" placeholder="IP" autocomplete="off" class="layui-input"></div>
                                
                                <div class="layui-input-inline layui-show-xs-block">
                                    <input type="text" name="logName" placeholder="请输入任务名称" autocomplete="off" class="layui-input"></div>
                                
                                <div class="layui-input-inline layui-show-xs-block">
                                    <button class="layui-btn" type="button"  onclick="sreach();">
                                        <i class="layui-icon">&#xe615;</i></button>
                                </div>
                            </form>
                            <div class="layui-card-body ">
                              <table class="layui-table layui-form" id="run">
                            </table>
                        </div>  
                    </div>
                </div>
            </div>
        </div>
    </body>
    <script type="text/javascript">
    layui.use(['laydate','form','table'],
        function() {
            var laydate = layui.laydate;

            //执行一个laydate实例
            laydate.render({
                elem: '#start' //指定元素
            });

            //执行一个laydate实例
            laydate.render({
                elem: '#end' //指定元素
            });
            
            var table = layui.table;
            //第一个实例
            table.render({
              elem: '#run',
              height: 312,
              url: 'taskLog/data', //数据接口
              method:'post',
              contentType: 'application/json; charset=UTF-8',
              //where:JSON.stringify(layui.form.field),
              page: true, //开启分页
              cols: [
            	      [
		                {field: 'id', title: 'ID', width:50, sort: true},
		                {field: 'logName', title: '任务名称', width:80},
		                {field: 'logClass', title: '任务类', width:80},
		                {field: 'logMethod', title: '任务方法', width:80},
		                {field: 'logIPPort', title: 'IP端口', width:120},
		                {field: 'logParam', title: '参数', width:100},
		                {field: 'logCorn', title: 'CORN表达式', width:100},
		                {field: 'logInsertDate', title: '执行时间', width:100},
		                {field: 'logStatus', title: '状态', width: 80,templet:'<div>{{ statusFormat(d.logStatus)}}</div>'},
		                {field: 'logMessage', title: '信息', width:80}
                      ]
            	    ]
            });
        });
    
    function statusFormat(statu) {
    	var msg="";
        if(0==statu){
        	msg="成功";
        }else if(-1==statu){
        	msg="失败";
        }else{
        	msg=" 未识别 ";
        }
        return msg;
    } 
    
    
    function sreach(){
    	var param=JSON.stringify(getFormJson($('#sreach')));
    	//alert(param);
    	layui.table.reload("run", { //此处是上文提到的 初始化标识id
            where: {
            	search:param
            }
        });
    	return false;
    }
    

    //将form中的值转换为键值对。
    function getFormJson(frm) {
        var o = {dosubmit:1};
        var a = $(frm).serializeArray();
        $.each(a, function () {
            if (o[this.name] !== undefined) {
                if (!o[this.name].push) {
                    o[this.name] = [o[this.name]];
                }
                o[this.name].push(this.value || '');
            } else {
                o[this.name] = this.value || '';
            }
        });
        return o;
    }
</script>
</html>